
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.Socket;

import javax.swing.JButton;
import javax.swing.JDesktopPane;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class NewJDialog extends javax.swing.JDialog {
	private JDesktopPane jDesktopPane1;
	private JButton jButton1;
	private JLabel jLabel1;
	private JTextField jTextField1;
	private java.net.Socket socket;
	private String host;
	private int port;
	
	public NewJDialog(JFrame frame,java.net.Socket s,String h,int p) {
		super(frame);
		this.socket = s;
		this.host=h;
		this.port=p;
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				jDesktopPane1 = new JDesktopPane();
				getContentPane().add(jDesktopPane1, BorderLayout.CENTER);
				{
					jTextField1 = new JTextField();
					jDesktopPane1.add(jTextField1);
					jTextField1.setBounds(28, 28, 343, 21);
				}
				{
					jButton1 = new JButton();
					jDesktopPane1.add(jButton1);
					jButton1.setText("SEND");
					jButton1.setBounds(126, 56, 98, 21);
					jButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButton1ActionPerformed(evt);
						}
					});
				}
				{
					jLabel1 = new JLabel();
					jDesktopPane1.add(jLabel1);
					jLabel1.setText("send system message:");
					jLabel1.setBounds(7, 7, 238, 14);
				}
			}
			this.setBounds(800, 300, 400, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void jButton1ActionPerformed(ActionEvent evt) {//
		System.out.println(0000);
		if(socket.isClosed()){
			System.out.println(1111);
			try{
				this.socket = new Socket(host,port);
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		System.out.println(2222);
		try{
			System.out.println(3333);
			java.io.OutputStream out = socket.getOutputStream();
			out.write("dia   ".getBytes());
			out.write(jTextField1.getText().getBytes());
			out.write("\r\n".getBytes());
			out.flush();
			System.out.println(4444);
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
				socket.close();
			}catch(Exception e){
				e.printStackTrace();
			}

		}

	}

}
